package com.mall.goods.service.impl;

import com.mall.goods.model.AdItems;
import com.mall.goods.mapper.AdItemsMapper;
import com.mall.goods.service.IAdItemsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * <p>
 * 商品推广表 服务实现类
 * </p>
 *
 * @author Darren
 * @since 2022-08-18
 */
@Service
public class AdItemsServiceImpl extends ServiceImpl<AdItemsMapper, AdItems> implements IAdItemsService {
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean addAdItems(AdItems aditems){
        return super.save(aditems);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean deleteById(Integer id){
        return super.removeById(id);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean updateAdItems(AdItems aditems){
        return super.updateById(aditems);
    }

    @Override
    public AdItems getById(Integer id){
        return super.getById(id);
    }

    @Override
    public List<AdItems> selectList(AdItems aditems){
        return super.list(getQueryWrapper(aditems));
    }

    @Override
    public Page<AdItems> selectPage(Page<AdItems> page, AdItems aditems){
        return super.page(page, getQueryWrapper(aditems));
    }

    public LambdaQueryWrapper<AdItems> getQueryWrapper(AdItems aditems){
        return Wrappers.<AdItems>lambdaQuery()
            .eq(ObjectUtils.isNotEmpty(aditems.getId()), AdItems::getId, aditems.getId())
            .eq(ObjectUtils.isNotEmpty(aditems.getName()), AdItems::getName, aditems.getName())
            .eq(ObjectUtils.isNotEmpty(aditems.getType()), AdItems::getType, aditems.getType())
            .eq(ObjectUtils.isNotEmpty(aditems.getSkuId()), AdItems::getSkuId, aditems.getSkuId())
            .eq(ObjectUtils.isNotEmpty(aditems.getSort()), AdItems::getSort, aditems.getSort())
        ;
    }
}
